package com.ls.admin.controller;

import com.ls.admin.service.AdminService;
import com.ls.pojo.*;
import com.ls.utils.Result;
import com.ls.utils.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("admin")
@CrossOrigin
public class AdminController {

    @Autowired
    private AdminService adminService;


    /**
     * 查询审核接口列表
     * @return
     */
    @GetMapping("/getAppInter")
    public Result getAppInter(){
        List<CustomerAppInter> customerAppInters = adminService.getAppInter();
        return new Result(true, StatusCode.OK,"查询成功",customerAppInters);
    }



    /**
     * 管理员审核用户申请接口
     * */
    @PostMapping(value = "/auditInterface")
    public Result auditInterface(@RequestBody CustomerAppInter customerAppInter,@RequestParam String adminName){
            if ("1".equals(customerAppInter.getStatus())){
                return new Result(false, StatusCode.AUDIT_PASS,"审核已通过");
            }

            adminService.auditInterface(customerAppInter,adminName);
            return new Result(true, StatusCode.AUDIT_PASS,"操作成功");
    }

    /**
     * 需要审核的个人列表
     * @return
     */
    @GetMapping("/getVeriPers")
    public Result getVeriPers(){
        List<VerifiedPersonal> verifiedPersonals = adminService.getVeriPers();
        return new Result(true, StatusCode.OK,"查询成功",verifiedPersonals);
    }

    /**
     * 需要审核的企业列表
     * @return
     */
    @GetMapping("/getVeriComp")
    public Result getVeriComp(){
        List<VerifiedCompany> verifiedCompanies = adminService.getVeriComp();
        return new Result(true, StatusCode.OK,"查询成功",verifiedCompanies);
    }

    /**
     * 管理员审核个人认证
     *
     * */
    @GetMapping(value = "/auditPerson")
    public Result auditPerson(@RequestParam String appid){
        adminService.auditPerson(appid);
        return new Result(true, StatusCode.OK,"操作成功");
    }

    /**
     * 管理员审核个人认证
     *
     * */
    @GetMapping(value = "/auditComp")
    public Result auditComp(@RequestParam String appid){
        adminService.auditComp(appid);
        return new Result(true, StatusCode.OK,"操作成功");
    }


    /**
     * 管理员查询自有接口
     *
     * */
    @GetMapping(value = "/getInterfaceList")
    public Result getInterfaceList(){
        List<InterVo> interList = adminService.getInterfaceList();
        return new Result(true,StatusCode.OK,"查询自有接口成功", interList);
    }

    /**
     *
     * 管理员查询第三方接口
     * */
    @GetMapping(value = "/getThirdpartyList")
    public Result getThirdpartyList(){
        List<InterThirdparty> thirdpartyList = adminService.getThirdpartyList();
        return new Result(true,StatusCode.OK,"查询第三方接口成功",thirdpartyList);
    }


    /**
     * 管理员对自己接口的删除
     *
     * */
    @PostMapping(value = "/deleteLocalInterface")
    public Result deleteLocalInterface(@RequestBody InterVo inter){

        adminService.deleteLocalInterface(inter);
        return new Result(true,StatusCode.OK,"删除本地接口成功");
    }


    @GetMapping("/getInterfaceDetail")
    public Result getInterfaceDetail(@RequestParam Integer id){
        InterVo interVo = adminService.getInterfaceDetail(id);
        return new Result(true,StatusCode.OK,"查询成功",interVo);
    }

    @PostMapping("/addreq")
    public Result addreq(@RequestBody InterReq interReq){
        int i= adminService.addreq(interReq);
        if(i != 1){
            return new Result(false,StatusCode.ERROR,"删除失败");
        }
        return new Result(true,StatusCode.OK,"操作成功");
    }

    @PostMapping("/addres")
    public Result addres(@RequestBody InterRes interRes){
        int i= adminService.addres(interRes);
        if(i != 1){
            return new Result(false,StatusCode.ERROR,"操作失败");
        }
        return new Result(true,StatusCode.OK,"操作成功");
    }

    @GetMapping("/delreq")
    public Result delreq(@RequestParam Integer id){
        int i= adminService.delreq(id);
        if(i != 1){
            return new Result(false,StatusCode.ERROR,"删除失败");
        }
        return new Result(true,StatusCode.OK,"删除成功");
    }

    @GetMapping("/delres")
    public Result delres(@RequestParam Integer id){
        int i= adminService.delres(id);
        if(i != 1){
            return new Result(false,StatusCode.ERROR,"删除失败");
        }
        return new Result(true,StatusCode.OK,"删除成功");
    }

    @PostMapping(value = "/addInter")
    public Result addInter(@RequestBody Inter inter){
        int i= adminService.addInter(inter);
        if(i != 1){
            return new Result(false,StatusCode.ERROR,"添加本地接口失败");
        }

        return new Result(true,StatusCode.OK,"添加本地接口成功");
    }





    /**
     * 添加自有接口
     *
     * */
    @PostMapping(value = "/addInterface")
    public Result addInterface(@RequestBody InterVo inter){
        adminService.addInterface(inter);


        return new Result(true,StatusCode.OK,"添加本地接口成功");
    }

    /**
     * 管理员对第三方接口的删除
     *
     * */
    @PostMapping(value = "/deleteThirdPartyInterface")
    public Result deleteThirdPartyInterface(@RequestBody InterThirdparty interThirdparty){
        adminService.deleteThirdPartyInterface(interThirdparty);
        return new Result(true,StatusCode.OK,"删除第三方接口成功");
    }


    /**
     * 管理员通过第三方接口id查询第三方接口
     * */
    @PostMapping(value = "/getThirdpartyById")
    public Result getThirdpartyById(@RequestBody InterThirdparty interThirdparty){
        InterThirdparty thirdparty=adminService.getThirdpartyById(interThirdparty);
        return new Result(true,StatusCode.OK,"查询通过id查询第三方接口成功",thirdparty);
    }

    /**
     *
     * 管理员添加第三方接口
     * */
    @PostMapping(value = "/addThirdparty")
    public Result addThirdparty(@RequestBody InterThirdparty interThirdparty){

        int i = adminService.addThirdparty(interThirdparty);
        if(i != 1){
            return new Result(false,StatusCode.ERROR,"添加第三方接口失败");
        }
        return new Result(true,StatusCode.OK,"添加第三方接口成功");
    }


    /**
     * 管理员修改第三方接口
     *
     * */
    @PostMapping(value = "/modifyThirdPartyInterface")
    public Result modifyThirdPartyInterface(@RequestBody InterThirdparty interThirdparty){
        adminService.modifyThirdPartyInterface(interThirdparty);
        return new Result(true,StatusCode.OK,"修改第三方接口成功");
    }

    /**
     * 管理员通过自有id查询自有接口
     * */
    @PostMapping(value = "/getInterfaceById")
    public Result getInterfaceById(@RequestBody InterVo inter){
        InterVo interVo=adminService.getInterfaceById(inter);
        return new Result(true,StatusCode.OK,"查询通过id查询自有接口成功",interVo);
    }

    /**
     * 管理员修改自有的接口
     *
     * */
    @PostMapping(value = "/modifyOwnInterface")
    public Result modifyOwnInterface(@RequestBody InterVo interVo){
        System.out.println(interVo.toString());
        adminService.modifyOwnInterface(interVo);

        return new Result(true,StatusCode.OK,"修改自有接口成功");
    }
}
